//
//  ONPowerMarketsByISOViewController.m
//  Volatix
//
//  Created by Nguyen Minh Duc on 6/2/14.
//  Copyright (c) 2014 Familly. All rights reserved.
//

#import "ONPowerMarketsByISOViewController.h"
#import "ONPowerMarketsByISOHeaderView.h"
#import "ONPowerMarketsByISOHeaderViewCellTableViewCell.h"
@interface ONPowerMarketsByISOViewController ()

@end

@implementation ONPowerMarketsByISOViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // hardcode
    self.dataArray = [[NSMutableArray alloc]initWithObjects:@"abc",@"d",@"c",@"abc",@"d",@"c",@"abc",@"d",@"c",@"abc",@"d",@"c",@"abc",@"d",@"c", nil];
    [self startPullDownRefresh];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    NSInteger numberOfCell = [self.dataArray count];
    return numberOfCell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // Add loading cell
    if (indexPath.row == [self.dataArray count]) {
        UITableViewCell *cell = [self getLoadingCellForTableView:tableView];
        return cell;
    } else {
        
        NSString *identifierString = @"ONPowerMarketsByISOHeaderViewCellTableViewCell";
        ONPowerMarketsByISOHeaderViewCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierString];
        if(cell == nil){
            cell = [[ONPowerMarketsByISOHeaderViewCellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierString];
        }
        
        [cell notCorner];
        if(indexPath.row == 29){
            [cell bottonCorner];
        }
        
        if(indexPath.row == 0){
            [cell topCorner];
        }
        
        if(indexPath.row %2 == 0){
            cell.v1.backgroundColor = kEventColorRow;
            cell.v2.backgroundColor = kEventColorRow;
            cell.v3.backgroundColor = kEventColorRow;
            cell.v4.backgroundColor = kEventColorRow;
            
        }else{
            cell.v1.backgroundColor = kOddColorRow;
            cell.v2.backgroundColor = kOddColorRow;
            cell.v3.backgroundColor = kOddColorRow;
            cell.v4.backgroundColor = kOddColorRow;
        }
        
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    ONPowerMarketsByISOHeaderView *view = [[ONPowerMarketsByISOHeaderView alloc]initWithFrame:CGRectMake(0, 0, 320, 100)];
    return view;
}


#pragma mark - UITableViewDelegate Methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // Deselect the row
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - Webservice Methods

// when pull down refresh, this method will be called
- (void)requestGetData {
    // hardcode
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:1];
}

@end
